﻿@using BlockMain_Class
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var s = (SelectBlock)Model;
    bool b = s.Msg == "ok";
}
<link rel="stylesheet" type="text/css" href="/assets/Css/selectcss.css" />

<body>
    <div class="bgimg">
        <div class="left">
            <div class="logo"></div>
        </div>
        <div class="right">
            <div class="top">
                <div class="user">
                    <img class="user-img" src="/Assets/Images/touxiang.png" />
                    <span class="txt">欢迎登录</span>
                </div>
                <div class="checkout">
                    <img class="checkout-img" src="/Assets/Images/fytuichu.png" />
                    <span class="txt" onclick="LoginOut()">退出</span>
                </div>
            </div>
            <div class="middle">
                <div class="contant">
                    <div class="title">
                        检测哈希值查询
                    </div>
                    <div class="input-part">
                        <div class="input">
                            <label>
                                HASH值：
                                <input type="text" placeholder="请输入有效的hash值" id="hash" value="@(b ? s.Hash : "")" />
                            </label>
                        </div>
                        <div class="button" onclick="select()">
                            查询
                        </div>
                    </div>
                    <div class="resualt-left" style="display: @(b ? "block" : "none")">
                        <div class="table1">
                            <table border="0" cellspacing="" cellpadding="">
                                <tr>
                                    <td style="" class="hxclass">哈希值:</td>
                                    <td colspan="3" id="hx">@(b ? s.Hash : "")</td>
                                </tr>
                                <tr>
                                    <th class="hxclass">类型:</th>
                                    <td id="jclx">@(b ? s.TypeName : "")</td>
                                    <th>交易时间:</th>
                                    <td id="jysj">@(b ? s.OrderAddTime : "")</td>
                                </tr>
                                <tr>
                                    <th class="hxclass">单位:</th>
                                    <td id="sjdw">@(b ? s.Mechanism : "")</td>
                                    <th class="hxclass">检测机构:</th>
                                    <td id="jcjg">@(b ? s.TestMechanism : "")</td>
                                </tr>
                            </table>
                        </div>
                        <div class="table2">
                            <table border="0" cellspacing="" cellpadding="">
                                <tr>
                                    <td colspan="4" style="font-size: 18px;">所在区块信息</td>
                                </tr>
                                <tr>
                                    <th class="hxclass">高度:</th>
                                    <td id="qkgd">@(b ? s.Heigth : 0)</td>
                                    <th>创建时间:</th>
                                    <td id="cjsj">@(b ? s.AddTime : "")</td>
                                </tr>
                                <tr>
                                    <th class="hxclass">上哈希:</th>
                                    <td colspan="3" id="syqk">@(b ? s.PrevHash : "")</td>
                                </tr>
                            </table>
                        </div>

                        <div class="table3">
                            <table border="0" cellspacing="" cellpadding="">
                                <tr>
                                    <td colspan="4" style="font-size: 18px;">共识信息</td>
                                </tr>
                                <tr>
                                    <th>共识确认节点</th>
                                    <th>共识确认时间</th>
                                    <th>共识确认状态</th>
                                </tr>
                                <tbody id="peerstate">
                                    @if (b)
                                    {
                                        foreach (var item in s.PeerState)
                                        {
                                            <tr>
                                                <td>@item.name</td>
                                                <td>@item.time</td>
                                                <td>@(item.state == 0 ? "已确认" : "未确认")</td>
                                            </tr>
                                        }
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="resualt" style="display: @(b ? "block" : "none")">
                        <p>
                            <!--startprint-->
                            <div class="print">
                                <div class="logo">
                                    <div class="first">
                                        <img src="/Assets/Images/jyb_2.png" />
                                    </div>
                                    <div class="second">
                                        <img src="/Assets/Images/jyb_1.png" />
                                    </div>
                                </div>
                                <h2>检  测  报  告  证  书</h2>
                                <div class="name">
                                    <div>
                                        <span id="sj">送检单位:@(b ? s.Mechanism : "")</span>
                                    </div>
                                    <div>
                                        <span id="jc">检测类型:@(b ? s.TypeName : "")</span>
                                    </div>
                                </div>
                                <table border="0" cellspacing="" cellpadding="">
                                    <tbody id="table">
                                        <tr>
                                            <th>项目名称</th>
                                            <th>是否合格</th>
                                            <th>完成时间</th>
                                        </tr>
                                        @if (b)
                                        {
                                            foreach (var item in s.ProjecItem)
                                            {
                                                <tr class="remove"><td>@(item.Name)</td><td>@(item.IsQualified ? "是" : "否")</td><td>@(item.SuceessTime)</td></tr>
                                            }
                                        }
                                    </tbody>
                                    <tr>
                                        <td colspan="3">报告原件：<font id="bg"> @(b ? !string.IsNullOrEmpty(s.FilePath) ? "http://121.43.191.79:4006/" + s.FilePath : "未上传" : "")</font></td>
                                    </tr>
                                </table>
                                <div class="seal">
                                    <div id="code" style="display:inline-block;width:49%;margin-top:20px;margin-left:10px"></div>
                                    <div class="first" style="display:inline-block;">
                                        <img src="@(b ? s.NowPeerUrl: "")" id="yz" />
                                    </div>
                                </div>
                            </div>
                            <!--endprint-->
                        </p>
                        <div class="noprint">
                            <!--class="noprint"的作用是标示不需要打印的地方，任何一个标签的class属性都可以设置，用于去除不需要打印的地方-->
                            <input type="button" value="打印" name="button_print" onclick="printpage()" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="~/js/jquery.qrcode.min.js"></script>
<script>
    $(function () {

         $('#code').qrcode({
                render: "canvas", //也可以替换为table
                width: 120,
                height: 120,
                text: "@(b ? s.Hash : "")"/*可以通过ajax请求动态设置*/

            })
            //将生成的二维码转换成图片格式
            var canvas = qrcode.find('canvas').get(0);
            $('#qrcodeImg').attr('src', canvas.toDataURL('image/jpg'));
        });
</script>
<script>
    function select() {
        var val = $("#hash").val();
        $.ajax({
            type: "POST",
            url: "/Show/GetInfo?Hash=" + val,
            dataType: "json",
            success: function (msg) {
                //处理json
                if (msg.msg == "ok") {
                    //基础
                    $("#hx").text(msg.hash);
                    $("#jclx").text(msg.typeName);
                    $("#jysj").text(msg.orderAddTime);
                    $("#sjdw").text(msg.mechanism);
                    $("#jcjg").text(msg.testMechanism);
                    $("#qkgd").text(msg.heigth);
                    $("#cjsj").text(msg.addTime);
                    $("#syqk").text(msg.prevHash);

                    //共识
                    var str1 = "";
                    $.each(msg.peerState, function (n, value) {
                        var isbool = "已确认";
                        if (value.state == 1) {
                            isbool = "未确认";
                        }
                        str1 += "<tr><td>" + value.name + "</td><td>" + value.time + "</td><td>" + isbool + "</td></tr>";
                    })
                    $("#peerstate").html(str1);

                    //证书
                    $("#sj").text(msg.mechanism);
                    $("#jc").text(msg.typeName);
                    $("#bg").text(msg.filePath != "" ? "http://116.62.224.147:8888/" + msg.filePath : "未上传");
                    $("#No").text(msg.hash);
                    $("#heigth").text(msg.heigth);
                    $("#yz").attr("src", msg.nowPeerUrl);
                    var str = "";
                    $.each(msg.projecItem, function (n, value) {
                        var isbool = "是";
                        if (!value.isQualified) {
                            isbool = "否";
                        }
                        str += "<tr class=\"remove\"><td>" + value.name + "</td><td>" + isbool + "</td><td>" + value.suceessTime + "</td></tr>";
                    })
                    $(".remove").remove();
                    $(".resualt").show();
                    $(".resualt-left").show();
                    $("#table").append(str);
                } else {
                    alert(msg.msg);
                }

            }
        });



    }

    //打开新页面启动打印
    function printpage() {
        //收起
        window.open("/show/print?hash=@(b?s.Hash:"")");
    }

</script>

